import request from '/@/utils/request';

enum Api {
	GetList = '/api/sysOrg/getList',
	GetTree = '/api/sysOrg/getTree',
	Add = '/api/sysOrg/add',
	Update = '/api/sysOrg/update',
	Delete = '/api/sysOrg/delete',
	BatchDelete = '/api/sysOrg/batchDelete',
}

// 机构实体
export interface SysOrg {
	// 主键Id
	id: number;
	// 父Id
	pid: number;
	// 名称
	name: string;
	// 编码
	code?: string;
	// 级别
	level?: number;
	// 机构类型
	type?: string;
	// 负责人Id
	directorId?: number;
	// 排序
	orderNo: number;
	// 状态
	status: number;
	// 备注
	remark?: string;
	// 租户Id
	tenantId: number;
	// 创建时间
	createTime: string;
	// 更新时间
	updateTime: string;
	// 创建者Id
	createUserId: number;
	// 创建者姓名
	createUserName: string;
	// 修改者Id
	updateUserId: number;
	// 修改者姓名
	updateUserName: string;
}

// 机构查询参数
export interface OrgInput {
	id?: number;
	tenantId?: number;
	name?: string;
	code?: string;
	type?: string;
}

// 机构树输出
export interface OrgTreeOutput {
	id: number;
	pid: number;
	name: string;
	code?: string;
	level?: number;
	type?: string;
	directorId?: number;
	orderNo: number;
	status: number;
	remark?: string;
	disabled: boolean;
	children?: OrgTreeOutput[];
}

// 机构管理接口服务
export const useSysOrgApi = () => {
	return {
		// 获取机构列表
		getList: (params?: OrgInput) =>
			request({
				url: Api.GetList,
				method: 'get',
				params,
			}),
		// 获取机构树
		getTree: (params?: OrgInput) =>
			request({
				url: Api.GetTree,
				method: 'get',
				params,
			}),
		// 新增机构
		add: (data: any) =>
			request({
				url: Api.Add,
				method: 'post',
				data,
			}),
		// 更新机构
		update: (data: any) =>
			request({
				url: Api.Update,
				method: 'post',
				data,
			}),
		// 删除机构
		delete: (data: any) =>
			request({
				url: Api.Delete,
				method: 'post',
				data,
			}),
		// 批量删除机构
		batchDelete: (data: any) =>
			request({
				url: Api.BatchDelete,
				method: 'post',
				data,
			}),
	}
}

